home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
'92_HACK
/
IR_MAN_
/
CD_ROM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-07
|
7KB
|
283 lines
#include "CD ROM.h"
short Decimal2BCD(short n) {
return ((n / 10) << 4) + (n % 10);
}
short BCD2Decimal(short n) {
return ((n >> 4) * 10) + (n & 0x0f);
}
/************************************************************************
*
* Function: AStop
*
* Purpose: stop playing an audio track
*
* Returns: OSErr. Probably either
* noErr everything's hunky-dory!
* paramErr you messed up the call somehow.
*
* Side Effects: stops play.
*
* Description: The track that you pass in is the LAST track that you
* want to have play. This means that if you wanted to
* play only one track, you'd pass the same value to
* this routine and APlay() [q.v.]
*
* Note that this routine isn't called in this sample,
* but it's included for your enjoyment.
*
************************************************************************/
OSErr
AStop(track, refNum)
short track;
short refNum;
{
struct {
short addrFormat;
long address;
} csParam;
csParam.addrFormat = TRACKADDR;
csParam.address = track;
return (Control(refNum, ASTOP, &csParam));
}
OSErr
APause(short state, short refNum) {
struct {
long pauseState; /* 1 pause, 0 play */
} csParam;
csParam.pauseState = state;
return (Control(refNum, APAUSE, &csParam));
}
OSErr
CDEject(short ioRefNum) {
OSErr osErr;
Str255 ioName;
HVolumeParam *pb;
pb = (HVolumeParam *) NewPtrClear(sizeof (*pb));
osErr = MemError();
if (0 != pb && noErr == osErr) {
(*pb).ioNamePtr = ioName;
(*pb).ioVolIndex = 0;
do {
++(*pb).ioVolIndex;
osErr = PBHGetVInfo((HParmBlkPtr)pb, false);
if (noErr != osErr) {
DisposPtr((Ptr) pb);
return osErr;
}
} while ((*pb).ioVRefNum != ioRefNum);
osErr = PBEject((ParmBlkPtr)pb);
if (noErr == osErr)
osErr = PBUnmountVol((ParmBlkPtr)pb);
DisposPtr((Ptr) pb);
}
return osErr;
}
/************************************************************************
*
* Function: APlay
*
* Purpose: start playing an audio track
*
* Returns: OSErr. Probably either
* noErr everything's hunky-dory!
* paramErr you messed up the call somehow.
*
* Side Effects: starts play. By default, this will play until the
* end of the disc.
*
* Description: The track that you pass in is the first track that you
* want to have play.
*
************************************************************************/
OSErr
APlay(track, refNum)
short track;
short refNum;
{
struct {
short addrFormat;
long address;
short stopAddress;
short playMode;
} csParam;
csParam.addrFormat = TRACKADDR;
csParam.address = track; /* must be in BCD */
csParam.stopAddress = 0;
csParam.playMode = STEREO;
return (Control(refNum, APLAY, &csParam));
}
/************************************************************************
*
* Function: Play
*
* Purpose: play a track, given it's "filename"
*
* Returns: OSErr
* whatever is returned by APlay()
*
* Side Effects: starts play of the audio track.
*
* Description: The two parameters passed in are the file name (which
* will always be of the form "Track XX", XX varying from
* " 1" to "99") and the driver reference number. Extract
* the track number and use it to call APlay() [q.v.]
*
************************************************************************/
OSErr
Play(track, driveNumber)
short track;
short driveNumber;
{
short trackBCD;
OSErr result;
short DriverNum;
trackBCD = Decimal2BCD(track);
DriverNum = GetDrvRefNum(driveNumber);
return( APlay(trackBCD, DriverNum) );
}
/************************************************************************
*
* Function: GetDrvRefNum
*
* Purpose: Get the driver reference number
*
* Returns: short. The driver reference number
*
* Side Effects: none.
*
* Description: PBHGetVInfo() will retrieve the driver reference
* number, given the vRefNum associated with a file.
* We acquired the vRefNum as something passed into
* the program, either by SFGetFile() or by
* GetAppFile().
*
* We'll use the driver reference number in all our
* control calls to the driver.
*
************************************************************************/
short
GetDrvRefNum(vRefNum)
short vRefNum;
{
HParamBlockRec io;
io.volumeParam.ioCompletion = NULL;
io.volumeParam.ioNamePtr = NULL;
io.volumeParam.ioVRefNum = vRefNum;
io.volumeParam.ioVolIndex = 0;
PBHGetVInfo(&io, false);
return io.volumeParam.ioVDRefNum;
}
OSErr
AScan(short state, short refNum) {
AudioStateStruct aState;
OSErr err;
auto AScanRec *pb;
err = AStatus(refNum, &aState);
if (err == noErr) {
pb = (AScanRec *) NewPtrClear(sizeof (*pb));
err = MemError();
if (0 != pb && noErr == err) {
(*pb).ioRefNum = refNum;
(*pb).csCode = ASCAN;
(*pb).csParam.commandType = MSFADDR;
(*pb).csParam.addr[1] = aState.absMinBCD;
(*pb).csParam.addr[2] = aState.absSecBCD;
(*pb).csParam.addr[3] = aState.absBlkBCD;
(*pb).csParam.direction = state;
err = PBControl((ParmBlkPtr)pb, false);
DisposPtr((Ptr) pb);
}
}
return err;
}
pascal OSErr
AStatus(short ioRefNum, AudioStateStruct *aState) {
auto OSErr osErr;
auto AStatusRec *pb;
pb = (AStatusRec *) NewPtrClear(sizeof (*pb));
osErr = MemError();
if (0 != pb && noErr == osErr) {
(*pb).ioRefNum = ioRefNum;
(*pb).csCode = ASTATUS;
osErr = PBControl((ParmBlkPtr)pb, false);
if (noErr == osErr) {
aState->aStatusFlags = (*pb).csParam.audioStatus;
aState->playMode = (*pb).csParam.playMode;
aState->controlField = (*pb).csParam.cntlField;
aState->absMinBCD = (*pb).csParam.minutes;
aState->absSecBCD = (*pb).csParam.seconds;
aState->absBlkBCD = (*pb).csParam.frames;
}
DisposPtr((Ptr) pb);
}
return osErr;
}
OSErr
ATrackSkip(short state, short refNum) {
OSErr err;
short track;
short extraTrack;
err = GetCurrTrack(refNum, &track);
if (err == noErr) {
if (state) {
extraTrack = BCD2Decimal(track);
extraTrack++;
track = Decimal2BCD(extraTrack);
}
else {
extraTrack = BCD2Decimal(track);
extraTrack--;
track = Decimal2BCD(extraTrack);
}
APlay(track, refNum);
}
return err;
}
pascal OSErr
GetCurrTrack(short ioRefNum, short *Track) {
auto OSErr osErr;
auto ReadQRec *pb;
pb = (ReadQRec *) NewPtrClear(sizeof (*pb));
osErr = MemError();
if (0 != pb && noErr == osErr) {
(*pb).ioRefNum = ioRefNum;
(*pb).csCode = csReadQ;
osErr = PBControl((ParmBlkPtr)pb, false);
if (noErr == osErr) {
*Track = (*pb).csParam.track;
}
DisposPtr((Ptr) pb);
}
return osErr;
}